package org.xg.study.boot.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author CMG
 * @version 1.0
 * @cLassName SwaggerConfig
 * @description
 * @date 2021/8/26 9:08
 **/
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {
    @Value("${swagger.enable}")
    private boolean swaggerShow = false;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(swaggerShow)
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.xg.study.boot.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建api的基本信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("RESTful APIs")
                .description("wx RESTful APIs")
                .termsOfServiceUrl("http://www.baidu.com")
                .contact(new Contact("xg", "www.baidu.com", "stdvn@outlook.com"))
                .version("1.0")
                .build();
    }
}
